473,421 Members | 1,668 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,421 software developers and data experts.

dropdown list maintains selection when back button is used.

I have two dropdown lists. Both have autopostback set to true. In both
dropdowns, when you select an item from the list, it redirects to the Value
property of the dropdown. Nothing fancy.

Let's say you select 1 of the items, and are properly redirected. You press
the back button. I have three servers providing two different
functionalities:

1. After pressing the back button, the item you selected in the dropdown is
still selected.
2. After pressing the back button, the default item in the dropdown is
selected again.

In the scenario number 1, if you postback again (let's say you now select
the OTHER dropdown list), *both* dropdown lists selected indexed changed
events fire. Or more precisely, one fires but the other does not because
the first one redirects before the second can fire.

I have copied the .dll and .aspx pages several times to confirm I am using
the same code.

Any ideas??? I would love the second scenario to be the default behavior in
all cases.

Thanks in advance.

Mark
Nov 18 '05 #1
6 10642
Drat. For good or for bad, you can easily recreate this on your own. I'd
LOVE to find a work around for this.

All you need to do is create a new web form, and add 2 dropdowns and a
checkbox. Make the id of the checkbox be "ckRedirect":

private void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack)
{
DropDownList1.Items.Add(new ListItem("1","a"));
DropDownList1.Items.Add(new ListItem("2","b"));
DropDownList1.Items.Add(new ListItem("3","c"));

DropDownList2.Items.Add(new ListItem("4","d"));
DropDownList2.Items.Add(new ListItem("5","e"));
DropDownList2.Items.Add(new ListItem("6","f"));

DropDownList1.AutoPostBack = true;
DropDownList2.AutoPostBack = true;
}
}
private void DropDownList1_SelectedIndexChanged(object sender,
System.EventArgs e)
{
Response.Write("<br>DDL1 selected index fired.");
if (ckRedirect.Checked)
Response.Redirect("http://www.cnn.com/");
}

private void DropDownList2_SelectedIndexChanged(object sender,
System.EventArgs e)
{
Response.Write("<br>DDL2 selected index fired.");
if (ckRedirect.Checked)
Response.Redirect("http://www.aol.com/");
}
"Mark" <mf****@idonotlikespam.cce.umn.edu> wrote in message
news:eK**************@TK2MSFTNGP11.phx.gbl...
I have two dropdown lists. Both have autopostback set to true. In both
dropdowns, when you select an item from the list, it redirects to the Value property of the dropdown. Nothing fancy.

Let's say you select 1 of the items, and are properly redirected. You press the back button. I have three servers providing two different
functionalities:

1. After pressing the back button, the item you selected in the dropdown is still selected.
2. After pressing the back button, the default item in the dropdown is
selected again.

In the scenario number 1, if you postback again (let's say you now select
the OTHER dropdown list), *both* dropdown lists selected indexed changed
events fire. Or more precisely, one fires but the other does not because
the first one redirects before the second can fire.

I have copied the .dll and .aspx pages several times to confirm I am using
the same code.

Any ideas??? I would love the second scenario to be the default behavior in all cases.

Thanks in advance.

Mark

Nov 18 '05 #2
Doubly interesting ... if you turn tracing ON and display it on the page
using your web.config file, this behavior goes away!

????

Ideas?

Thanks in advance.

Mark
"Mark" <mf****@idonotlikespam.cce.umn.edu> wrote in message
news:eK**************@TK2MSFTNGP11.phx.gbl...
I have two dropdown lists. Both have autopostback set to true. In both
dropdowns, when you select an item from the list, it redirects to the Value property of the dropdown. Nothing fancy.

Let's say you select 1 of the items, and are properly redirected. You press the back button. I have three servers providing two different
functionalities:

1. After pressing the back button, the item you selected in the dropdown is still selected.
2. After pressing the back button, the default item in the dropdown is
selected again.

In the scenario number 1, if you postback again (let's say you now select
the OTHER dropdown list), *both* dropdown lists selected indexed changed
events fire. Or more precisely, one fires but the other does not because
the first one redirects before the second can fire.

I have copied the .dll and .aspx pages several times to confirm I am using
the same code.

Any ideas??? I would love the second scenario to be the default behavior in all cases.

Thanks in advance.

Mark

Nov 18 '05 #3
Hi Mark,

When a user hits the back button the page does not go back to the server.
It is shown in the same state as the user left it. Internet Explorer even
returns them to the same position on the page they had scrolled to before
leaving. In order to make this work you need to find out if an event fires
client-side when the page is re-displayed using the back button. If there
is one, then put your client-side code in there to reset your dropdowns. I
don't know of one off the top of my head but if I get a chance I'll look
into it. This should set you on the right path though. Good luck! Ken.

--
Ken Dopierala Jr.
For great ASP.Net web hosting try:
http://www.webhost4life.com/default.asp?refid=Spinlight

"Mark" <mf****@idonotlikespam.cce.umn.edu> wrote in message
news:eK**************@TK2MSFTNGP11.phx.gbl...
I have two dropdown lists. Both have autopostback set to true. In both
dropdowns, when you select an item from the list, it redirects to the Value property of the dropdown. Nothing fancy.

Let's say you select 1 of the items, and are properly redirected. You press the back button. I have three servers providing two different
functionalities:

1. After pressing the back button, the item you selected in the dropdown is still selected.
2. After pressing the back button, the default item in the dropdown is
selected again.

In the scenario number 1, if you postback again (let's say you now select
the OTHER dropdown list), *both* dropdown lists selected indexed changed
events fire. Or more precisely, one fires but the other does not because
the first one redirects before the second can fire.

I have copied the .dll and .aspx pages several times to confirm I am using
the same code.

Any ideas??? I would love the second scenario to be the default behavior in all cases.

Thanks in advance.

Mark

Nov 18 '05 #4
Hi Mark,

It appears that the onload() event fires after the back button takes you to
the previous page. Add the onload() event to your <body> tag and when it
fires reset your drop down lists with client-side javascript. Then you
should be all set. Good luck! Ken.

"Ken Dopierala Jr." <kd*********@wi.rr.com> wrote in message
news:Oc**************@TK2MSFTNGP12.phx.gbl...
Hi Mark,

When a user hits the back button the page does not go back to the server.
It is shown in the same state as the user left it. Internet Explorer even
returns them to the same position on the page they had scrolled to before
leaving. In order to make this work you need to find out if an event fires client-side when the page is re-displayed using the back button. If there
is one, then put your client-side code in there to reset your dropdowns. I don't know of one off the top of my head but if I get a chance I'll look
into it. This should set you on the right path though. Good luck! Ken.

--
Ken Dopierala Jr.
For great ASP.Net web hosting try:
http://www.webhost4life.com/default.asp?refid=Spinlight

"Mark" <mf****@idonotlikespam.cce.umn.edu> wrote in message
news:eK**************@TK2MSFTNGP11.phx.gbl...
I have two dropdown lists. Both have autopostback set to true. In both
dropdowns, when you select an item from the list, it redirects to the Value
property of the dropdown. Nothing fancy.

Let's say you select 1 of the items, and are properly redirected. You

press
the back button. I have three servers providing two different
functionalities:

1. After pressing the back button, the item you selected in the dropdown

is
still selected.
2. After pressing the back button, the default item in the dropdown is
selected again.

In the scenario number 1, if you postback again (let's say you now select the OTHER dropdown list), *both* dropdown lists selected indexed changed
events fire. Or more precisely, one fires but the other does not because the first one redirects before the second can fire.

I have copied the .dll and .aspx pages several times to confirm I am using the same code.

Any ideas??? I would love the second scenario to be the default

behavior in
all cases.

Thanks in advance.

Mark


Nov 18 '05 #5
i like this idea a lot. thanks! HOWEVER, my gut wonders if the onload()
event would cause problems when you select an item from the Dropdown each
time. When the page posts back, the onload() would fire and wipe out what
the user selected. I'm nervous the dropdown code would then fire, but use
the incorrect (default) value??

Just typing theoretically here ... thanks again.

mark
"Ken Dopierala Jr." <kd*********@wi.rr.com> wrote in message
news:eF**************@TK2MSFTNGP09.phx.gbl...
Hi Mark,

It appears that the onload() event fires after the back button takes you to the previous page. Add the onload() event to your <body> tag and when it
fires reset your drop down lists with client-side javascript. Then you
should be all set. Good luck! Ken.

"Ken Dopierala Jr." <kd*********@wi.rr.com> wrote in message
news:Oc**************@TK2MSFTNGP12.phx.gbl...
Hi Mark,

When a user hits the back button the page does not go back to the server.
It is shown in the same state as the user left it. Internet Explorer even returns them to the same position on the page they had scrolled to before leaving. In order to make this work you need to find out if an event

fires
client-side when the page is re-displayed using the back button. If there is one, then put your client-side code in there to reset your dropdowns.

I
don't know of one off the top of my head but if I get a chance I'll look
into it. This should set you on the right path though. Good luck! Ken.
--
Ken Dopierala Jr.
For great ASP.Net web hosting try:
http://www.webhost4life.com/default.asp?refid=Spinlight

"Mark" <mf****@idonotlikespam.cce.umn.edu> wrote in message
news:eK**************@TK2MSFTNGP11.phx.gbl...
I have two dropdown lists. Both have autopostback set to true. In both dropdowns, when you select an item from the list, it redirects to the

Value
property of the dropdown. Nothing fancy.

Let's say you select 1 of the items, and are properly redirected. You

press
the back button. I have three servers providing two different
functionalities:

1. After pressing the back button, the item you selected in the dropdown
is
still selected.
2. After pressing the back button, the default item in the dropdown is
selected again.

In the scenario number 1, if you postback again (let's say you now

select the OTHER dropdown list), *both* dropdown lists selected indexed
changed events fire. Or more precisely, one fires but the other does not

because the first one redirects before the second can fire.

I have copied the .dll and .aspx pages several times to confirm I am using the same code.

Any ideas??? I would love the second scenario to be the default

behavior
in
all cases.

Thanks in advance.

Mark



Nov 18 '05 #6
Hi Mark,

If your page posts back to the server and instead of redirecting to another
page displays itself again, then this would cause a problem. You will need
to keep some type of state to know when to actually run the code in your
onload event. The easiest way would be to create a hidden HTML input field
with the runat="server" attribute set. If your page posts back to itself
and needs to keep the current drop down state then set this value to 1 on
the server side code. In the function you call from the onload event check
this field. If it is 0 then reset your list boxes. If it is 1 then ignore
the listboxes and instead reset this variable to 0. You need to do the
reset to 0 client-side because if you did it server side and then to a
redirect it would never get back to your page and when they hit the back
button the value would still be 1 and the list boxes wouldn't reset. Good
luck! Ken.

--
Ken Dopierala Jr.
For great ASP.Net web hosting try:
http://www.webhost4life.com/default.asp?refid=Spinlight

"Mark" <mf****@idonotlikespam.cce.umn.edu> wrote in message
news:%2***************@TK2MSFTNGP11.phx.gbl...
i like this idea a lot. thanks! HOWEVER, my gut wonders if the onload()
event would cause problems when you select an item from the Dropdown each
time. When the page posts back, the onload() would fire and wipe out what
the user selected. I'm nervous the dropdown code would then fire, but use
the incorrect (default) value??

Just typing theoretically here ... thanks again.

mark
"Ken Dopierala Jr." <kd*********@wi.rr.com> wrote in message
news:eF**************@TK2MSFTNGP09.phx.gbl...
Hi Mark,

It appears that the onload() event fires after the back button takes you

to
the previous page. Add the onload() event to your <body> tag and when it
fires reset your drop down lists with client-side javascript. Then you
should be all set. Good luck! Ken.

"Ken Dopierala Jr." <kd*********@wi.rr.com> wrote in message
news:Oc**************@TK2MSFTNGP12.phx.gbl...
Hi Mark,

When a user hits the back button the page does not go back to the server. It is shown in the same state as the user left it. Internet Explorer even returns them to the same position on the page they had scrolled to before leaving. In order to make this work you need to find out if an event

fires
client-side when the page is re-displayed using the back button. If there is one, then put your client-side code in there to reset your dropdowns. I
don't know of one off the top of my head but if I get a chance I'll
look into it. This should set you on the right path though. Good luck!

Ken.
--
Ken Dopierala Jr.
For great ASP.Net web hosting try:
http://www.webhost4life.com/default.asp?refid=Spinlight

"Mark" <mf****@idonotlikespam.cce.umn.edu> wrote in message
news:eK**************@TK2MSFTNGP11.phx.gbl...
> I have two dropdown lists. Both have autopostback set to true. In both > dropdowns, when you select an item from the list, it redirects to the Value
> property of the dropdown. Nothing fancy.
>
> Let's say you select 1 of the items, and are properly redirected. You press
> the back button. I have three servers providing two different
> functionalities:
>
> 1. After pressing the back button, the item you selected in the dropdown is
> still selected.
> 2. After pressing the back button, the default item in the dropdown is > selected again.
>
> In the scenario number 1, if you postback again (let's say you now

select
> the OTHER dropdown list), *both* dropdown lists selected indexed changed > events fire. Or more precisely, one fires but the other does not

because
> the first one redirects before the second can fire.
>
> I have copied the .dll and .aspx pages several times to confirm I am

using
> the same code.
>
> Any ideas??? I would love the second scenario to be the default

behavior
in
> all cases.
>
> Thanks in advance.
>
> Mark
>
>



Nov 18 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
dmjpro
by: dmjpro | last post by:
i saw some magic web pages ..... when press back button then the same page again and again reloaded ... is it possible in js ...... plz help me out ... thanx in advnace .......
0
by: Frank | last post by:
Hi, I've applied a SSL cert to a portion of my website, which brings the user to an https://mysite/login/Login.aspx page. After successfully logging in, the user can browse around freely in the...
6
by: lucyh3h | last post by:
Hi, In one of my pages, I use javascript (AJAX) to populate one mulitple select field based on user's click event on another control. I noticed that when I navigate back to this page by clicking...
1
by: ARAVIND999 | last post by:
PLEASE SEND THE SOURCE CODE FOR THE ABOVE MENTIONED STATEMENT.(i.e., HOW TO EXPIRE THE PAGE WHEN BACK BUTTON IS PRESSED)
1
by: Rob | last post by:
I know this is an old one, considering how many posts I found on it but I just wondered if any best practises had popped up recently, especially as Ajax has increased JavaScript and DHTML's...
1
rrocket
by: rrocket | last post by:
I have a page with radio buttons that either enable or disable textboxes depending on the radio button selection. When the user clicks submit the they are taken to a thank you page, but if they hit...
1
by: jeet232 | last post by:
Hi, how can I get to know when user clicks browser back button? I want my own javascript code to be executed when this happens. Also, is there a way that whenever any link in the page is clicked,...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.